//
//  upShiftHeadView.m
//  基本框架
//
//  Created by runone02 on 2018/8/6.
//  Copyright © 2018年 liqiyun. All rights reserved.
//

#import "upShiftHeadView.h"
#import "LoginViewController.h"
#import "ZMRegisterViewController.h"
#import "BaseNavigationController.h"
@implementation upShiftHeadView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    //tableView的headView
    self.HeadImageView = [[UIImageView alloc]init];
    self.HeadImageView.userInteractionEnabled = YES;
    self.HeadImageView.image = IMAGE(@"mineNavBar");
    [self addSubview:self.HeadImageView];
    
    [self.HeadImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(self);
    }];
    
    
    self.lineView = [[UIView alloc]init];
    self.lineView.backgroundColor = [UIColor whiteColor];
    [self.HeadImageView addSubview:self.lineView];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.HeadImageView);
        make.bottom.mas_equalTo(self.HeadImageView).with.offset(-W_RATIO(50));
        make.width.mas_equalTo(1);
        make.height.mas_equalTo(20);
    }];
    
    
    self.loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.loginButton setTitle:@"登录" forState:UIControlStateNormal];
    [self.loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.loginButton.titleLabel.font = TITLE_FONT(30);
    [self.loginButton addTarget:self action:@selector(loginButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.HeadImageView addSubview:self.loginButton];
    
    [self.loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.lineView);
        make.right.mas_equalTo(self.lineView.mas_left).with.offset(-W_RATIO(20));
    }];
    
    self.registeButton = [UIButton buttonWithType: UIButtonTypeCustom];
    [self.registeButton setTitle:@"注册" forState:UIControlStateNormal];
    [self.registeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.registeButton addTarget:self action:@selector(registeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    self.registeButton.titleLabel.font = TITLE_FONT(30);
    [self.HeadImageView addSubview:self.registeButton];
    
    [self.registeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.lineView);
        make.left.mas_equalTo(self.lineView.mas_right).with.offset(W_RATIO(20));
    }];
    
    
//    //头像
    self.headImg = [UIButton buttonWithType:UIButtonTypeCustom];//
    [self.headImg setImage:IMAGE(@"gestureHead") forState:UIControlStateNormal];
    [self.headImg addTarget:self action:@selector(headImageClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.HeadImageView addSubview:self.headImg];

    [self.headImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.lineView);
        make.right.mas_equalTo(self.loginButton.mas_left).with.offset(-W_RATIO(20));
        make.width.mas_equalTo(W_RATIO(60));
        make.height.mas_equalTo(W_RATIO(60));
    }];
}

- (void)headImageClick:(UIButton *)btn{
    NSLog(@"点击了头像");
}

- (void)registeButtonClick:(UIButton *)btn{
    ZMRegisterViewController *vc = [[ZMRegisterViewController alloc] init];
    [self.viewController.navigationController pushViewController:vc animated:YES];
   
}

- (void)loginButtonClick:(UIButton *)btn{
    
    btn.enabled = NO;
    LoginViewController *vc = [[LoginViewController alloc] init];
    //如果登录视图需要push的话就需要包装导航控制器
    BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:vc];
    [self.viewController presentViewController:nav animated:YES completion:^{
        btn.enabled = YES;
    }];
}
@end
